package business {

    import com.adobe.cairngorm.business.ServiceLocator;
    
    import mx.collections.*;
    import mx.rpc.*;
    import mx.rpc.remoting.*;
	
    public class BookDelegate
    {
		private var responder:Object;
        private var service:RemoteObject;

        public function BookDelegate(re:Object)
        {
	        this.service = ServiceLocator.getInstance().getRemoteObject("bookService");
            this.responder = re;
        }
        
        public function getBooks(page:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getBooks(page);
            itemResponder = new ItemResponder(responder["getBooksResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function getBooksByAuditGood(page:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getBooksByAuditGood(page);
            itemResponder = new ItemResponder(responder["getBooksByAuditGoodResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function getBooksByAudit(page:int,range:String="unaudit"):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getBooksByAudit(page,range);
            itemResponder = new ItemResponder(responder["getBooksForAuditResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }

        public function getBooksById(ids:Array):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getBooksById(ids);
            itemResponder = new ItemResponder(responder["getBooksByIdResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function getBooksBySearch(pattern:String, type:String, page:int=0,showAssetType:int=3):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getBooksBySearch(pattern,type,page,showAssetType);
            itemResponder = new ItemResponder(responder["getBooksBySearchResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }      
        
        public function getBooksByAuditGoodBySearch(pattern:String, type:String, page:int=0):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getBooksByAuditGoodBySearch(pattern,type,page);
            itemResponder = new ItemResponder(responder["getBooksBySearchResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }        
                 
        public function removeBooks(page:int,ids:Array):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.removeBooks(page,ids);
            itemResponder = new ItemResponder(responder["removeBooksResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }              

        public function updateBook(ids:Array,update:Object):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.updateBook(ids,update);
            itemResponder = new ItemResponder(responder["updateBookResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function getWords():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getWords();
            itemResponder = new ItemResponder(responder["getWordsResult"],responder["fault"] );
            token.addResponder(itemResponder);        	
        } 
		
		
		public function backToQiqu(id:int):void
		{
			var token:AsyncToken;
			var itemResponder:ItemResponder;
			token = service.backToQiqu(id);
			itemResponder = new ItemResponder(responder["backToQiquResult"],responder["fault"] );
			token.addResponder(itemResponder);    
		}
		
    }
}

